<?php
/**
 * Author:xsc
 * Time:2023/9/5 18:49
 */

namespace App\Repository;

use App\Models\SpecialOpenOrder;

class SpecialOpenOrderRepo extends BaseRepo
{

    /**
     * 新增/更新订单
     * @param array $data
     * @param int $id
     * @return int
     * Author:xsc
     * Time:2023/9/6 15:45
     */
    public function save(array $data, int $id = 0)
    {
        if ($id) {
            return SpecialOpenOrder::query()->where('id', $id)->update($data);
        } else {
            return SpecialOpenOrder::query()->insertGetId($data);
        }
    }

    /**
     * 根据外部订单号查询订单
     * @param string $out_order_no
     * @return array
     * Author:xsc
     * Time:2023/9/5 19:14
     */
    public function getByOutOrderNo(string $out_order_no)
    {
        $res = SpecialOpenOrder::query()->where('out_order_no', $out_order_no)->where('is_delete', 0)->first();
        return $res ? $res->toArray() : [];
    }

}
